package com.wondersgroup.wuhan_demo.widget;

import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wondersgroup.wuhan_demo.R;

/**
 * Created by liyaqing on 2018/5/8 0008.
 */

public class GuideTopWidget extends LinearLayout {
    private int guidePosition=1;
    private LinearLayout llGuideTop;
    private TextView tvInfo;
    private TextView tvKs;
    private TextView tvHy;
    private TextView tvYy;

    private Context mContext;
    private Resources resources;

    public GuideTopWidget(Context context) {
        super(context);
        mContext=context;
        initView(context,null);
    }

    public GuideTopWidget(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        mContext=context;
        initView(context,attrs);
    }

    public GuideTopWidget(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mContext=context;
        initView(context,attrs);
    }

    private void initView(Context context,  AttributeSet attrs) {
        resources = mContext.getResources();
        //初始化布局
        View view = LayoutInflater.from(context).inflate(R.layout.guide_top_widget, this, true);
        llGuideTop = view.findViewById(R.id.ll_guide_top);
        tvInfo=view.findViewById(R.id.tv_info);
        tvKs=view.findViewById(R.id.tv_ks);
        tvHy=view.findViewById(R.id.tv_hy);
        tvYy=view.findViewById(R.id.tv_yy);

        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GuideTopWidget);
          int guideposition=a.getInt(R.styleable.GuideTopWidget_guidePosition,1);
          this.guidePosition=guideposition;
        setSelectState(guidePosition);
        a.recycle();

    }

    public int getGuidePosition() {
        return guidePosition;
    }

    public void setGuidePosition(int guidePosition) {
        this.guidePosition = guidePosition;
        setSelectState(guidePosition);

    }
    private void setSelectState(int guidePosition){
        switch (guidePosition) {
            case 1:
                llGuideTop.setBackground(resources.getDrawable(R.mipmap.gh_bg1));
                tvInfo.setTextColor(resources.getColor(R.color.white));
                tvKs.setTextColor(resources.getColor(R.color.text_gray));
                tvHy.setTextColor(resources.getColor(R.color.text_gray));
                tvYy.setTextColor(resources.getColor(R.color.text_gray));
                break;
            case 2:
                llGuideTop.setBackground(resources.getDrawable(R.mipmap.gh_bg2));
                tvInfo.setTextColor(resources.getColor(R.color.text_gray));
                tvKs.setTextColor(resources.getColor(R.color.white));
                tvHy.setTextColor(resources.getColor(R.color.text_gray));
                tvYy.setTextColor(resources.getColor(R.color.text_gray));
                break;
            case 3:
                llGuideTop.setBackground(resources.getDrawable(R.mipmap.gh_bg3));
                tvInfo.setTextColor(resources.getColor(R.color.text_gray));
                tvKs.setTextColor(resources.getColor(R.color.text_gray));
                tvHy.setTextColor(resources.getColor(R.color.white));
                tvYy.setTextColor(resources.getColor(R.color.text_gray));
                break;
            case 4:
                llGuideTop.setBackground(resources.getDrawable(R.mipmap.gh_bg4));
                tvInfo.setTextColor(resources.getColor(R.color.text_gray));
                tvKs.setTextColor(resources.getColor(R.color.text_gray));
                tvHy.setTextColor(resources.getColor(R.color.text_gray));
                tvYy.setTextColor(resources.getColor(R.color.white));
                break;

        }
        }
}
